package com.system.healthproject.model.sickuser.controller;

import com.system.healthproject.annotation.RequireToken;
import com.system.healthproject.bean.PagesBean;
import com.system.healthproject.common.ApiResult;
import com.system.healthproject.model.admin.paramsbean.VisitRecordsParams;
import com.system.healthproject.model.sickuser.service.DiseaseLogService;
import com.system.healthproject.pojo.DiseaseLog;
import com.system.healthproject.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(value = "患者端-病情日志",tags = "患者端-病情日志API")
@RestController
@RequestMapping("/sickuser/diseselog")
@Validated
public class DiseaseLogUserController {

    @Autowired
    RedisUtil redisUtil;
    @Autowired
    DiseaseLogService diseaseLogService;


    @RequireToken
    @ApiOperation(value = "新增病情日志(后端已调)",notes = "新增病情日志",httpMethod = "post")
    @PostMapping(value = "/addDiseaseLog",produces = "application/json;charset=utf-8")
    public ApiResult addDiseaseLog(@Validated@RequestBody
                                       @ApiParam(required = true)
                                               DiseaseLog diseaseLog,
                                     @RequestHeader("token")String token){
        Object token1 = redisUtil.get(token);
        Map<String, Object> map = (Map<String, Object>) token1;
        Integer loginId = (Integer) map.get("loginId");
        diseaseLogService.addDiseaseLog(diseaseLog,loginId);
        return ApiResult.withBoolean(true);
    }

    @RequireToken
    @ApiOperation(value = "患者获取病情日志列表(后端已调)",notes = "新增病情日志",httpMethod = "post")
    @GetMapping(value = "/getDiseaseLogList",produces = "application/json;charset=utf-8")
    public ApiResult<PagesBean<Map<String, Object>>> getDiseaseLogList(
            @RequestParam(required = false,name = "page") int page,
            @RequestParam(required = false,name = "size") int size,
                                   @RequestHeader("token")String token){
        Object token1 = redisUtil.get(token);
        Map<String, Object> map = (Map<String, Object>) token1;
        Integer loginId = (Integer) map.get("loginId");

        PagesBean<Map<String, Object>> diseaseLogList =
                diseaseLogService.getDiseaseLogList(page, size, loginId);
        return ApiResult.successWithData(diseaseLogList);
    }

}
